/*
    Marv the Miner for Nokia Series 30, 40 and 60 and for selected MIDP 1.0 supported phones
    Copyright (C) 2003-2004  Digital Entertainment Europe AS (http://www.digiment.no)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
	
    If you have any questions, please contact support@digiment.no
*/
import javax.microedition.lcdui.*;

public class Frame
{
	int x;
	int y;

	int w;	// full size
	int h;

	int fw;	// one frame size
	int fh;

	int index;	// image index

	static int x1,y1,x2,y2,ix,delay;

	public Frame(int index,int x,int y,int w,int h,int fw,int fh)
	{
		this.index = index;
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
		this.fw = fw;
		this.fh = fh;
		ix = 0;
		delay = 0;
	}

	int next()
	{
		if (delay <= 0)
		{
			delay = 4;
			ix += fw;
		}
		else delay--;
		if (ix >= w) ix = 0;
		return ix;
	}

	void draw(int gx,int gy)
	{
		Main.gd.setClip(gx,gy,fw,fh);
		Main.gd.drawImage(Main.img[index],gx - x,gy - y,20); // Graphics.TOP | Graphics.LEFT
	}

	void draw(int gx,int gy,int cx,int cy,int cw,int ch)
	{
		x1 = gx > cx ? gx : cx;
		y1 = gy > cy ? gy : cy;
		x2 = gx + fw < (cx + cw) ? gx + fw : cx + cw;
		y2 = gy + fh < (cy + ch) ? gy + fh : cy + ch;
		Main.gd.setClip(x1,y1,x2 - x1,y2 - y1);
		Main.gd.drawImage(Main.img[index],gx - x,gy - y,20);
	}
}

